package com.foodcommunity.service.impl;

import com.foodcommunity.entity.Tag;
import com.foodcommunity.mapper.TagMapper;
import com.foodcommunity.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TagServiceImpl implements TagService {

    @Autowired
    private TagMapper tagMapper;

    @Override
    public List<Tag> getAllTags() {
        return tagMapper.selectAll();
    }

    @Override
    public Tag getTagById(Long id) {
        return tagMapper.selectById(id);
    }

    @Override
    public void createTag(Tag tag) {
        tag.setCreateTime(System.currentTimeMillis());
        tag.setUpdateTime(System.currentTimeMillis());
        tag.setPostCount(0);
        tagMapper.insert(tag);
    }

    @Override
    public void updateTag(Tag tag) {
        tag.setUpdateTime(System.currentTimeMillis());
        tagMapper.update(tag);
    }

    @Override
    public void deleteTag(Long id) {
        tagMapper.deleteById(id);
    }
} 